package com.heima.wemedia.controller.v1;

import com.heima.model.admin.dtos.SensitivePageReqDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmSensitiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author atom.hu
 * @version V1.0
 * @Package com.heima.wemedia.controller.v1
 * @date 2021/12/22 13:18
 */
@RestController
@RequestMapping("/api/v1/sensitive")
public class VmSensitiveController {

    @Autowired
    private WmSensitiveService sensitiveService;

    @PostMapping("/list")
    public ResponseResult list(@RequestBody SensitivePageReqDto dto){
        return sensitiveService.list(dto);
    }

    @DeleteMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable Integer id){
        return sensitiveService.deleteById(id);
    }

    @PostMapping("/update")
    public  ResponseResult update(@RequestBody WmSensitive dto){
        boolean result = sensitiveService.updateById(dto);
        if (!result){
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,"修改失败");
        }
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @PostMapping("/save")
    public  ResponseResult save(@RequestBody WmSensitive dto){
        boolean flag = sensitiveService.save(dto);
        if (!flag){
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,"添加失败");
        }
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
